package com.tyk.bookstore.front.product.model.entity;


import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tyk.bookstore.front.common.core.util.FileUtil;
import com.tyk.bookstore.front.product.model.enume.BookState;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;


/**
 * @author tyk
 * @description 书籍DO
 */
@Schema(name = "Book", description = "书籍")
@TableName("book")
@Data
public class BookDo implements Serializable {

    @Serial
    private static final long serialVersionUID = 1;
    @Schema(description = "ID")

    public static final Long NOT_EXIST = 0L;


    @TableId("id")
    private Long id;

    @Schema(description = "书籍编号")
    @TableField("book_no")
    private String bookNo;

    @Schema(description = "书名")
    @TableField("name")
    private String name;

    @Schema(description = "价格")
    @TableField("price")
    private BigDecimal price;

    @Schema(description = "封面路径")
    @TableField("cover")
    private String cover;

    @Schema(description = "标题")
    @TableField("title")
    private String title;

    @Schema(description = "书籍简介")
    @TableField("summary")
    private String summary;

    @Schema(description = "作者ID")
    @TableField("author_id")
    private Long authorId;

    @Schema(description = "出版社ID")
    @TableField("publisher_id")
    private Long publisherId;

    @Schema(description = "出版时间")
    @TableField("publish_time")
    private LocalDateTime publishTime;

    @Schema(description = "ISBN")
    @TableField("isbn")
    private String isbn;

    @Schema(description = "低级分类ID")
    @TableField("classification_id")
    private Long classificationId;

    @Schema(description = "字数[单位：千字]")
    @TableField("word_num")
    private Long wordNum;

    @Schema(description = "重量（单位：克）")
    @TableField("weight")
    private Long weight;

    @Schema(description = "规格")
    @TableField("format")
    private Integer format;

    @Schema(description = "状态[0下架，1上架]")
    @TableField("state")
    private BookState state;

    @Schema(description = "创建时间")
    @TableField("create_time")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    @TableField("update_time")
    private LocalDateTime updateTime;

    public BookDo setCover(String cover) {
        this.cover = FileUtil.relativePath(cover);
        return this;
    }
}
